package com.zmn.plat.admin.controller.orderconfig.documentarycontent;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.zmn.common.constant.GlobalConsts;
import com.zmn.common.dictionary.GlobalDict;
import com.zmn.common.dto2.ResponseDTO;
import com.zmn.mcc.common.dto.dept.DeptDRO;
import com.zmn.plat.model.entity.orderconfig.documentarycontent.DocumentaryContentQuery;
import com.zmn.plat.model.vo.orderconfig.documentarycontent.DocumentaryContentVO;

/**
 * 类描述:跟单内容列表控制器
 *
 * @author linfeng
 * @since 2019/10/21/14:46
 */
@Controller
@RequestMapping(value = "/orderconfig/documentarycontent/")
public class DocumentaryContentListController extends DocumentaryContentBaseController {
    private Logger logger = LoggerFactory.getLogger(DocumentaryContentListController.class);

    @RequestMapping(value = "list")
    @RequiresPermissions("/orderconfig/documentarycontent/list.action")
    @SuppressWarnings("Duplicates")
    public ModelAndView list(@ModelAttribute DocumentaryContentQuery query) {
        List<DocumentaryContentVO> items = documentaryContentBService.listPageByQuery(query);
        List<Integer> fourPlatId =
            Arrays.asList(GlobalConsts.ZMN_ORGAN_ID, GlobalConsts.YEYX_ORGAN_ID, GlobalConsts.YBSH_ORGAN_ID, GlobalConsts.CNHB_ORGAN_ID);
        ResponseDTO<List<DeptDRO>> data = deptListRemoteService.listDeptByOrgIds(fourPlatId, GlobalConsts.YES);
        List<DeptDRO> departments = new ArrayList<>();
        if (data.isSuccess()) {
            departments = data.getData();
        }

        ModelAndView mav = new ModelAndView("orderconfig/documentarycontent/list");
        mav.addObject("vo", query);
        mav.addObject("items", items);
        mav.addObject("bizTypeList", com.zmn.plat.common.dictionary.ProductDict.listBizType());
        mav.addObject("departments", departments);
        return mav;
    }

    @RequestMapping(value = "detail")
    @RequiresPermissions("/orderconfig/documentarycontent/detail.action")
    @SuppressWarnings("Duplicates")
    public ModelAndView detail(@RequestParam(value = "id", defaultValue = "0") Integer id) {
        DocumentaryContentVO documentaryContentVO;
        if (id > 0) {
            documentaryContentVO = documentaryContentBService.findByKey(id);
        } else {
            documentaryContentVO = new DocumentaryContentVO();
        }

        List<Integer> fourPlatId =
            Arrays.asList(GlobalConsts.ZMN_ORGAN_ID, GlobalConsts.YEYX_ORGAN_ID, GlobalConsts.YBSH_ORGAN_ID, GlobalConsts.CNHB_ORGAN_ID);
        ResponseDTO<List<DeptDRO>> data = deptListRemoteService.listDeptByOrgIds(fourPlatId, GlobalConsts.YES);
        List<DeptDRO> departments = new ArrayList<>();
        if (data.isSuccess()) {
            departments = data.getData();
        }

        ModelAndView mav = new ModelAndView("orderconfig/documentarycontent/detail");
        mav.addObject("bizTypeList", com.zmn.plat.common.dictionary.ProductDict.listBizType());
        mav.addObject("statuses", GlobalDict.getStatusList(false));
        mav.addObject("vo", id);
        mav.addObject("documentaryContentVO", documentaryContentVO);
        mav.addObject("departments", departments);
        return mav;
    }
}
